<extend name="common:base" />
<block name="content">
	<div id="header">
		<div class="header">
			<h1 class="tit">{$site_title}</h1>
			<!--<p class="goback">-->
				<!--<a class="return" href="{:U('Recharge/rechargecenter')}">返回</a>-->
			<!--</p>-->
			<!--<p class="more"><a class="share" href=""></a></p>-->
		</div>
	</div>
	<form action="{:U('Recharge/rechargepage')}" method="post" id="save_form" enctype="multipart/form-data">
	<div class="banx-a">
			<div class="a-1">
				<div class="cz-img">
					<notempty name="avatar['avatar']">
						<img name="head" src="{$avatar['avatar']}"/>
						<else/>
						<img class="photo" name="head" src="./Public/images/default.png"/>
					</notempty>
				</div>
				<div class="cz-name">
					<p><a>{$userinfo['agent_name']}</a></p>
					<p><a>{$userinfo['mobile']}</a></p>
				</div>
			</div>
			<div class="a-2">
				<div class="a-2b">
					<div class="qian">
						<p>充值金额</p>
						<input type="text" placeholder="请输入充值金额" name="rechargemoney" id=rechargemoney"/>
					</div>
				</div>
				<div class="a-2b">
					<div class="qian">
						<p>充值备注</p>
						<input type="text" placeholder="请输入充值备注" name="rechargeps" id=rechargeps"/>
					</div>
				</div>
				<div class="a-2c">
					<div class="qian">
						<p>充值截图</p>
						<div class="qian-box">
							<img onclick="getElementById('file').click()" src="__PUBLIC__/images/add1.png">
							<img type="hidden" class="img-show" >
						</div>
							<input  type="file" name='file' id="file" style="display: none"/>
					</div>
				</div>
			</div>
			<span class="tj" id="save">提交审核</span>
            <span class="tj" id="show" style="display: none">提交中</span>
		</div>
	</form>
</block>
<block name="CSS">
	<link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/congzhi.css" />
	<link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/uploadifive.css" />
	<link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/zoomify.css" />
</block>
<block name="JS">
	<script type="text/javascript" src="{:C('__STATIC__')}{$theme}/Static/js/zoomify.js"></script>
	<script type="text/javascript" src="{:C('__STATIC__')}{$theme}/Static/js/jquery.uploadifive.js"></script>
	<script>
        $(function () {
            //图片预览
            $('#file').change(function() {
                var file = $('#file').get(0).files[0];

                if (typeof(file) ==  'object') {
                    var size = file.size;
                    var fileSize=Math.round(size/1024*100)/100;
                    if (fileSize > 1024) {
                        layer.msg('图片不得超过1024KB!', {icon: 2, time: 1000});
                        return false;
                    }

                    var reader = new FileReader();
                    reader.readAsDataURL(file);
                    reader.onload=function(e){
                        $('.img-show').attr('src', e.target.result);
                    }
                } else {
                    $('.img-show').attr('src','');
                }
            });

            $(".img-show").click(function () {
                var url =$(".img-show")[0].src;
                layer.open({
                    type: 1,
                    title: false,
                    closeBtn: 1,
                    shadeClose: false,
                    area: '80%' ,//宽高
                    content: "<img src=" + url + " style='height:60%;width:100%' class='img-big' />"
                });
            });


            $('#save').click(function() {
                var rechargemoney = $('input[name="rechargemoney"]').val();
                var brandname = $("#brandname option:selected").val();
                var rechargeps = $('input[name="rechargeps"]').val();
                var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
                var file = $('#file').val();

                if (!reg.test(rechargemoney)) {
                    layer.msg('请填写正确的金额', {time: 1500});
                    return false;
                }
                if (file == '') {
                    layer.msg('请上传图片', {time: 1500});
                    return false;
                }
                $("#save").hide();
                $("#show").show();
                $("#save_form").ajaxSubmit({
                    url: "{:U('Recharge/Recharge')}",
                    type:'post',
                    data: {
                        'img': $('#file').val(),
                        'rechargemoney': rechargemoney,
                        'brandname': brandname,
                        'rechargeps': rechargeps
                    },  beforeSend: function () {
                        layer.msg('申请提交中..', {icon: 16,time:500});
                    },
					success: function() {
                        layer.msg("提交成功",{icon:1,time:1000});
                        setTimeout(function () {
                            window.location.href = "{:U('Recharge/rechargecenter')}";
                        }, 1000);
                    }
                });
            });
        });
	</script>
</block>
